package com.shenjialin.Game;

import com.shenjialin.Tank.Tank;
import com.shenjialin.util.MyUtil;

import java.awt.*;

/**
 * 用来控制爆炸效果的类
 */
public class Explode {
    public static final int EXPLODE_FRAME_COUNT = 8;

    private static int explodeWidth = Tank.RADIUS;
    private static Image[] img;
    static {
        img = new Image[EXPLODE_FRAME_COUNT >> 1];
        for (int i = 0; i < img.length; i++) {
            img[i] = MyUtil.createImage("res/baozha" + i + ".jpg");
        }
    }

    // 爆炸效果的属性

    private int x,y;
    // 当前播放动画的帧数
    private int index;
    private boolean visible;

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public void draw(Graphics g) {
        if (!visible) {
            return;
        }
        g.drawImage(img[index >> 1], this.x, this.y, null);
        index++;
        // 播放完最后一帧
        if (index >= EXPLODE_FRAME_COUNT) {
            setVisible(false);
        }
    }

    public Explode() {
        index = 0;
    }

    public Explode(int x, int y) {
        this.x = x- (explodeWidth>>2);
        this.y = y- (explodeWidth>>2);

        index = 0;
        visible = true;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x- (explodeWidth);
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y- (explodeWidth);
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }
}
